package com.explorex.infra.puma.gateway.netty.ws.message;

import com.explorex.infra.puma.gateway.netty.ws.enums.MessageTypeEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @author: JacceYang
 * @createTime: 2022/07/15 10:18 上午
 * @description:
 */
@Data
public class Message implements Serializable {

    private MessageHeader header;

    /**
     * Message body type ,can be binary or string ,or MessageBodyType
     */
    private Object body;

    public static Message buildAck(Object response, MessageHeader reqHeader, MessageTypeEnum messageTypeEnum) {
        Message message = new Message();

        long time = System.currentTimeMillis();
        MessageHeader respHeader = new MessageHeader(messageTypeEnum.getType());
        respHeader.trackHeader(reqHeader);
        message.setHeader(respHeader);
        message.getHeader().setTs(time);
        message.setBody(response);
        return message;
    }
}
